//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import yzService from "components/ui_components/yz_service";
import yzGoodsposter from "components/ui_components/yz_goodsPoster";
import cMyswipe from "components/myswipe";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {yzService,cMyswipe,yzGoodsposter},
  data() {
  return {
    status:1,
    slideBanner:[
      {
        image_url:'https://dev8.yunzmall.com/static/upload/image/803deae708f9e2ce52f8c9f20ea77537.jpg'
      }
    ],
    applyInfo:{},
    swiperOption: {
      autoplay: false,
      // loop: true,   loop模式第二轮循环的时候第一张会闪烁
      delay: 3000,
      observer: true,
      pagination: {
        el: ".swiper-pagination",
        type: "fraction",
      }
    },
    iPnoneBottomBol: false, //是否是苹果手机
    id:'',
    endTime:'',
    goodsImg:[],
    //客服插件
    serviceShow: false,
    serviceQRcode: "",
    serviceMobile: "",
    cservice: "",
    // thumbLink:''
    // 海报按钮
    posterShow: false,
    posterImg: null,
    isFrontCanvas: false, //是否前端控制生成海报，false为后端生成
    btnData2: {
      over_top: 450,
      icon_url: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/bc_eweima.png"
    },
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getiPnoneBottom() { //检测是否为苹果手机
      var userAgent = navigator.userAgent;
      var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      isiOS?this.iPnoneBottomBol = true:this.iPnoneBottomBol = false;
    },
    applyOn(title,id) {
      this.$router.push(this.fun.getUrl('applyForm', {}, {goodsId:id,title:title}));
    },
    postShow() {
      // 显示海报
      this.$nextTick(()=> {
        this.$refs.priceTitleRepertorySales.postShow();
      });
    },
    goodsDetail() { //会员信息
      let urlStr = app.getNetAddresss("plugin.event-registration.api.goods.goods.get-goods-detail");
      app._postNetWork({
        url: urlStr,
        data: {basic_info:1,id:this.data.id},
        success: (resdata) => {
          var res = resdata.data;
          let data = res.data;
          if (res.result == 1) {
            this.setData({
              applyInfo:data,
              endTime:data.time
            })
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
   
    onService() {
      this.serviceShow = true;
    },
    endTimeFun(endTime) {
      let date = endTime * 1000;
      // let timeDate = date.getTime();
      let current = new Date().getTime();
      return date - current;
    },
    goodsDetail() {
      $http.get("plugin.event-registration.api.goods.goods.get-goods-detail", {id:this.id}, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
           this.applyInfo = res;
          this.endTime = this.applyInfo.time * 1000;
          } else {
            
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    serviceDetail() {
      $http.post("goods.customer-service.index", { goods_id: this.id }, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.cservice = res.cservice;
            this.serviceQRcode = res.service_QRcode;
            this.serviceMobile = res.service_mobile;
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          console.log(response);
        }
      );
    },
     //海报生成
     postShow() {
      if (!this.fun.isTextEmpty(this.posterImg)) {
        this.posterShow = true;
      } else {
        let toastPoster = this.$toast({
          duration: -1, // 持续展示 toast
          message: "正在为您生成海报中"
        });
        let url = "";
        let Jons = {};
        // this.isFrontCanvas = false;
        // this.isFrontCanvas = true;
        // url = "plugin.yz-supply-cake.frontend.goods.goods-poster.new-goods-poster";
        url = 'goods.goods-poster.new-goods-poster';
        Jons.id = this.id;
        $http
          .get(url, Jons, "")
          .then(response => {
            toastPoster.clear();
            if (response.result == 1) {
              // isFrontCanvas 是否需要前端生成海报
              // this.posterImg = this.isFrontCanvas ? response.data : `${response.data.image_url}?${Date.now()}`;
              this.posterImg = response.data.image_url;
              console.log(this.posterImg)
              console.log(this.isFrontCanvas);
              this.posterShow = true;
            } else {
              this.posterShow = false;
              this.$dialog.alert({ message: response.msg });
            }
          })
          .catch(error => {
            toastPoster.clear();
            console.log(error);
          });
      }
      // this.posterShow = true;
      this.showSahre = true;
    },
    posterClick() {
      this.postShow();
    },
    posterClose() {
      this.posterShow = false;
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    if (this.$route.params.id) {
      this.id = Number(this.$route.params.id);
      this.goodsDetail();
    }
    this.getiPnoneBottom();
    this.serviceDetail();
    
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }